package com.jxsm.service.impl;

import com.jxsm.dao.BaseDao;
import com.jxsm.dao.FactoryDao;
import com.jxsm.page.Page;
import com.jxsm.pojo.Factory;
import com.jxsm.service.FactoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.*;

/**
 * Created by Administrator on 2016/10/30.
 */
@Service
public class FactoryServiceimpl implements FactoryService{
    @Autowired
    private FactoryDao factoryDao;


    public void addFactory(Factory entity) {
        entity.setId(UUID.randomUUID().toString());//设置uuid
        entity.setCreateTime(new Date());
        entity.setState(1);//设置启用状态
       factoryDao.insert(entity);
    }

    public void updateFactory(Factory entity) {
        factoryDao.update(entity);
    }

    public void deleteById(Serializable id) {
        factoryDao.deleteById(id);
    }

    public void deleteFactory(Serializable[] id) {
        factoryDao.delete(id);
    }

    public List<Factory> findPage(Page page) {
        return factoryDao.findPage(page);
    }

    public List<Factory> find(Map map) {
        return factoryDao.findAll(map);
    }

    public Factory getFactory(Serializable id) {
        return factoryDao.get(id);
    }

    public void start(Serializable[] id) {
        Map<String ,Object> map=new HashMap();
        map.put("state",1);
        map.put("ids",id);
        factoryDao.updateState(map);
    }

    public void stop(Serializable[] id) {
        Map<String ,Object> map=new HashMap();
        map.put("state",0);
        map.put("ids",id);
        factoryDao.updateState(map);
    }
//只查询启用状态的生产厂家
public List<Factory> list() {
        Map<String,Object> map=new HashMap();
        map.put("state",1);
        return factoryDao.findAll(map);
        }
        }
